package qsou.rpc.framework.common.utils;

import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Properties;
import lombok.extern.slf4j.Slf4j;

/**
 * @description:
 * @auther: wuxw
 * @Date: 2022/3/29 15:45
 */
@Slf4j
public class PropertiesFileUtil {
  private PropertiesFileUtil(){

  }
  public static Properties readPropertiesFile(String fileName) {
    URL url = Thread.currentThread().getContextClassLoader().getResource("");
    String recConfigPath = "";
    if (url != null) {
      recConfigPath = url.getPath() + fileName;
    }

    Properties properties = null;
    try {
      InputStreamReader inputStreamReader = new InputStreamReader(
          new FileInputStream(recConfigPath), StandardCharsets.UTF_8);
      properties = new Properties();
      properties.load(inputStreamReader);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return properties;
  }
}